/*     */ package com.asiainfo.dacp.catalog.controller;
/*     */ 
/*     */ import com.asiainfo.dacp.jdbc.JdbcTemplate;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.SQLException;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.jdbc.core.PreparedStatementSetter;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/catalog"})
/*     */ public class MetaCatalogController
/*     */ {
/*  28 */   private static Logger LOG = LoggerFactory.getLogger(MetaCatalogController.class);
/*     */   
/*     */   @RequestMapping(value={"/autocatalog"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*  32 */   public Object catalog(HttpServletRequest request, HttpServletResponse response) { Map<String, String> result = new HashMap();
/*     */     
/*  34 */     String catatype = request.getParameter("catatype");
/*  35 */     String setcode = request.getParameter("setcode");
/*     */     try
/*     */     {
/*  38 */       if ("resource".equals(catatype)) {
/*  39 */         catalogRes(setcode);
/*  40 */       } else if ("busi".equals(catatype)) {
/*  41 */         catalogBusi(setcode);
/*     */       }
/*  43 */       result.put("message", "自动归档成功！");
/*     */     } catch (Exception e) {
/*  45 */       e.printStackTrace();
/*  46 */       result.put("message", "归档出错！");
/*  47 */       result.put("error", e.getMessage());
/*     */     }
/*     */     
/*  50 */     return result;
/*     */   }
/*     */   
/*     */   private void catalogRes(String dbname) throws Exception {
/*  54 */     JdbcTemplate template = new JdbcTemplate();
/*  55 */     List<Map<String, Object>> tops = template.queryForList("SELECT RULECODE, RULEDEF FROM METADB_STRUCT WHERE DBNAME = '" + dbname + "' AND (RULETYPE = 'TOPICCODE' OR RULETYPE = 'TOPICNAME')");
/*  56 */     for (Map<String, Object> m : tops) {
/*  57 */       String topiccode = (String)m.get("RULECODE");
/*  58 */       String ruledef = (String)m.get("RULEDEF");
/*  59 */       String[] rules = ruledef.split(",");
/*     */       
/*  61 */       if ((rules.length == 1) && ("".equals(rules[0]))) {
/*  62 */         rules = new String[0];
/*     */       }
/*     */       
/*  65 */       for (int i = 0; i < rules.length; i++) {
/*  66 */         List<Map<String, Object>> tabs = template.queryForList("SELECT XMLID FROM TABLEFILE WHERE (DATANAME LIKE '%" + rules[i] + "%' OR DATACNNAME LIKE '%" + rules[i] + "%') AND DBNAME = '" + dbname + "'");
/*  67 */         if (tabs.size() != 0)
/*     */         {
/*     */ 
/*  70 */           for (Map<String, Object> tab : tabs) {
/*  71 */             String xmlid = (String)tab.get("XMLID");
/*  72 */             template.execute("UPDATE TABLEFILE SET TOPICCODE = '" + topiccode + "' WHERE XMLID = '" + xmlid + "'");
/*  73 */             template.execute("UPDATE METAOBJ SET TOPICCODE = '" + topiccode + "' WHERE XMLID = '" + xmlid + "'");
/*     */           } }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void catalogBusi(String setcode) throws Exception {
/*  80 */     JdbcTemplate template = new JdbcTemplate();
/*  81 */     List<Map<String, Object>> catas = template.queryForList("SELECT RULECODE, RULEDEF FROM METADB_STRUCT WHERE DBNAME = '" + setcode + "' AND (RULETYPE = 'TOPICCODE' OR RULETYPE = 'TOPICNAME')");
/*  82 */     for (Map<String, Object> m : catas) {
/*  83 */       final String catacode = (String)m.get("RULECODE");
/*  84 */       String ruledef = (String)m.get("RULEDEF");
/*  85 */       String[] rules = ruledef.split(",");
/*     */       
/*  87 */       if ((rules.length == 1) && ("".equals(rules[0]))) {
/*  88 */         rules = new String[0];
/*     */       }
/*     */       
/*  91 */       for (int i = 0; i < rules.length; i++) {
/*  92 */         List<Map<String, Object>> objs = template.queryForList("SELECT XMLID, DBNAME, OBJTYPE, OBJNAME FROM METAOBJ WHERE OBJTYPE = 'TAB' AND (OBJNAME LIKE '%" + rules[i] + "%' OR OBJCNNAME LIKE '%" + rules[i] + "%')");
/*  93 */         if (objs.size() != 0)
/*     */         {
/*     */ 
/*  96 */           for (Map<String, Object> obj : objs) {
/*  97 */             final String xmlid = (String)obj.get("XMLID");
/*  98 */             final String set = setcode;
/*  99 */             final String objtype = (String)obj.get("OBJTYPE");
/* 100 */             final String objname = (String)obj.get("OBJNAME");
/*     */             
/* 102 */             int count = ((Integer)template.queryForObject("SELECT COUNT(1) FROM METADB_STRUCT_OBJ WHERE XMLID = '" + xmlid + "' AND DBNAME = '" + set + "'", Integer.class)).intValue();
/* 103 */             if (count == 0) {
/* 104 */               String sql = "INSERT INTO METADB_STRUCT_OBJ (XMLID, RULECODE, DBNAME, OBJTYPE, OBJNAME) VALUES (?, ?, ?, ?, ?)";
/* 105 */               template.update(sql, new PreparedStatementSetter()
/*     */               {
/*     */                 public void setValues(PreparedStatement ps) throws SQLException {
/* 108 */                   ps.setString(1, xmlid);
/* 109 */                   ps.setString(2, catacode);
/* 110 */                   ps.setString(3, set);
/* 111 */                   ps.setString(4, objtype);
/* 112 */                   ps.setString(5, objname);
/*     */                 }
/*     */               });
/*     */             }
/*     */             else
/*     */             {
/* 118 */               template.execute("UPDATE METADB_STRUCT_OBJ SET RULECODE = '" + catacode + "' WHERE XMLID = '" + xmlid + "' AND DBNAME = '" + set + "'");
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              C:\Users\my\.m2\repository\com\asiainfo\dacp\dacp-dataos\1.0.0\dacp-dataos-1.0.0.jar!\com\asiainfo\dacp\catalog\controller\MetaCatalogController.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */